#!/bin/bash
#author merci
#暴力破解mysql密码 for Centos6.x

CONF="/etc/my.cnf"
NEWPASS="你的新密码"

ROWS=`cat $CONF | grep -n "[mysql]" | head -1 | awk -F ':' '{print $1}'`
INSERTROWS=`expr $ROWS + 1`
sed -i "${INSERTROWS}i\skip-grant-tables" $CONF
/etc/init.d/mysqld restart >/dev/null
mysql -u root -p\n << EOF
use mysql;
update user set password=password("$NEWPASS") where user="root";
flush privileges;
exit
EOF
sed -i "/skip-grant-tables/d" $CONF >/dev/null 2>&1
/etc/init.d/mysqld restart >/dev/null
exit 1